export function dataURLtoBlob(dataurl) {
  let arr = dataurl.split(',')
  let mime = arr[0].match(/:(.*?);/)[1]
  let bstr = atob(arr[1])
  let n = bstr.length
  let u8arr = new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  return new Blob([u8arr], {
    type: mime,
  })
}

export function GMTToStr(time) {
  let date = new Date(time)
  var month = date.getMonth() + 1
  var day = date.getDate()
  if (month >= 10) {
    month = month
  } else {
    month = '0' + month
  }
  if (day >= 10) {
    day = day
  } else {
    day = '0' + day
  }
  let Str = date.getFullYear() + '/' + month + '/' + day
  return Str
}

export const removePropertyOfNull = function(obj) {
  Object.keys(obj).forEach((item) => {
    if (obj[item] === '') delete obj[item]
    if (item.indexOf('$') !== -1) delete obj[item]
    if (typeof obj[item] == 'string') {
      obj[item] = obj[item].trim()
    }
  })
  return obj
}
